<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">已接取任务</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>已接取任务</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：
            <select id="taskIntercept-search-key">
                <option value="">-请选择-</option>
                <option value="nkname">发布者</option>
                <option value="tkcode">任务编号</option>
            </select>&emsp;
            <input id="taskIntercept-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="taskIntercept-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="taskIntercept-table" lay-filter="taskIntercept-table"></table>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="taskIntercept-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="replyAuthor">对作者留言</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="editReply">查看和修改留言</a>
</script>

<script>
    layui.use(['form', 'table', 'util', 'config', 'admin'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;
        let index = layui.index;
        let userinfo = '';

        index.getUser(function (user) {
            userinfo = user;
        });

        // 渲染表格
        table.render({
            elem: '#taskIntercept-table',
            // url: config.base_server + 'user_query.json',
            url: config.base_server + 'api-task/task/findMyInterceptTasks',
            method: 'GET',
            where: {
                access_token: config.getToken().access_token,
                userid: userinfo.id
            },
            page: true,
            cols: [[
                {type: 'numbers'},
                {field: 'nkname', sort: true, title: '发布者'},
                {field: 'tkcode', sort: true, title: '任务编号'},
                {field: 'integr', sort: true, title: '积分'},
                {
                    sort: true, templet: function (d) {
                        return util.toDateString(d.cretim);
                    }, title: '发布时间'
                },
                {field: 'endtim', sort: true, title: '任务结束时间'},
                {align: 'center', toolbar: '#taskIntercept-table-bar', title: '操作', width: 250},
                ]]

        });

        // 回复按钮点击事件
        // $('#taskIntercept-btn-add').click(function () {
        //     showReplyModel(data);
        // });

        // 工具条点击事件
        table.on('tool(taskIntercept-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'editReply') {
                showEditReplyModel(data);
            } else if (layEvent === 'replyAuthor'){
                showReplyModel(data);
            }
            });

        let showReplyModel = function (data) {
            admin.putTempData('t_taskIntercept', data);
            admin.popupCenter({
                title: '留言发布者',
                path: 'pages/task/task_intercept_form.html',
                area: ['800px', '800px'],
                finish: function () {
                    table.reload('taskIntercept-table', {});
                }
            });
        };

        let showEditReplyModel = function (data) {
            admin.putTempData('t_taskIntercept', data);
            admin.popupCenter({
                title: '查看和修改留言',
                path: 'pages/task/task_intercept_editReoly.html',
                area: ['800px', '800px'],
                finish: function () {
                    table.reload('taskIntercept-table', {});
                }
            });
        };

        // 搜索按钮点击事件
        $('#taskIntercept-btn-search').click(function () {
            var key = $('#taskIntercept-search-key').val();
            var value = $('#taskIntercept-search-value').val();
            table.reload('taskIntercept-table', {where: {searchKey: key, searchValue: value}});
            // console.log(key,value,2323);
        });
    });
</script>